package com.heyun.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.heyun.bean.HeyunService;
import com.heyun.dao.HeyunServiceDao;
import com.heyun.service.HeyunServiceService;

@Service
public class HeyunServiceImpl implements HeyunServiceService{
	@Autowired
	private HeyunServiceDao heyunServiceDao; ;
	public Map listHeyunService(HeyunService heyunService,int currentPage){
		PageHelper.startPage(currentPage,2);
		/*SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);*/
		List<HeyunService> heyunServiceList=heyunServiceDao.listHeyunService(heyunService);
		PageInfo<HeyunService> p=new PageInfo<HeyunService>(heyunServiceList);
		Map map=new HashMap();
		map.put("heyunServiceList",heyunServiceList);
		for(HeyunService hl:heyunServiceList){
			System.out.println(hl+"HAA");
		}
		map.put("totalPage",p.getPages());
	
		return map;
	}
	public int insertHeyunService(HeyunService heyunService){
/*		SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);*/
		int a=heyunServiceDao.insertHeyunService(heyunService);
	
		return a;
	}
	public int updateHeyunService(HeyunService heyunService){
		System.out.println(heyunService+"ooi");
/*		SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);*/
		int a=heyunServiceDao.updateHeyunService(heyunService);

		return a;
	}
	public int deleteHeyunService(HeyunService heyunService){
/*		SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);*/
		int a=heyunServiceDao.deleteHeyunService(heyunService);

		return a;
	}
	/*//质疑其存在的意义
	public int updateHeyunServiceExtra(HeyunService heyunService){
		SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);
		int a=heyunServiceDao.updateHeyunService(heyunService);
		session.commit();
		session.close();
		return a;
	}*/
	public HeyunService getHeyunServiceExtra(HeyunService heyunService){
/*		SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);*/
		HeyunService heyunServiceResult=heyunServiceDao.getHeyunServiceExtra(heyunService);
		System.out.println(heyunServiceResult.toString());
		return heyunServiceResult;
	}
	public int archivesHeyunService(int[] checkID){
/*		SqlSession session=sqlSessionFactory.openSession();
		HeyunServiceDao heyunServiceDao=session.getMapper(HeyunServiceDao.class);*/
		int a=heyunServiceDao.archivesHeyunService(checkID);
		return a;
	}
}
